#!/usr/bin/env bash
# Summary: List all available plenv commands
# Usage: plenv commands [--sh|--no-sh]

set -e
[ -n "$PLENV_DEBUG" ] && set -x

case "$1" in
--complete ) # Provide plenv completions
  echo --sh
  echo --no-sh
  exit
  ;;
--sh )
  sh=1
  ;;
--no-sh )
  nosh=1
  ;;
esac


IFS=: paths=($PATH)

shopt -s nullglob

{ for path in "${paths[@]}"; do
    for command in "${path}/plenv-"*; do
      command="${command##*plenv-}"
      case "$command" in
        sh-*) [ -n "$nosh" ] && continue ;;
           *) [ -n "$sh"   ] && continue ;;
      esac
      echo ${command##sh-}
    done
  done
} | sort -u
